import TSpace.Tuple;

public class ClientTests {
    static private Client client;
    static private String serverMachineName;
    static private String serverMachinePort;

    public static void setUp() {
        client = new Client(ClientTests.serverMachineName, ClientTests.serverMachinePort, 1);
    }
    
    public static void testSayHello() {
//        client.sayHello();
    }

    public static void testWriteTuple() {
    	/* Writes 3 tuples */
    	assert(client.write("Jose", TupleType.STRING));
    	assert(client.write("Jose", TupleType.STRING, 22, TupleType.INT));
    	assert(client.write("Jose", TupleType.STRING, 22, TupleType.INT, 'M', TupleType.CHAR));
    }
    
    public static void testReadTuple() {
    	Tuple tuple = client.read(TupleType.STRING, TupleType.INT, TupleType.CHAR);
    	System.out.println("numElements: " + tuple.numElements);
    	assert(tuple.numElements == ((short) 3));
    	assert(tuple.e1.extract_string().equals("Jose"));
    	assert(tuple.e2.extract_long() == 22);
    	assert(tuple.e3.extract_char() == 'M');
    }
    
    public static void testTakeTuple() {
    	Tuple tuple = client.take(TupleType.STRING, TupleType.INT, TupleType.CHAR);
    	System.out.println("numElements: " + tuple.numElements);
    	assert(tuple.numElements == ((short) 3));
    	assert(tuple.e1.extract_string().equals("Jose"));
    	assert(tuple.e2.extract_long() == 22);
    	assert(tuple.e3.extract_char() == 'M');
    }

    public static void runAllTests(String serverMachineName, String serverMachinePort) {
        ClientTests.serverMachineName = serverMachineName;
        ClientTests.serverMachinePort = serverMachinePort;
        setUp();
        testSayHello();

        //~ setUp();
        testWriteTuple();
        //~ setUp();
        testReadTuple();
        //~ setUp();
        testTakeTuple();
    }
    
    public static void main(String args[]) {
        try{
            String serverMachineName = "localhost";
            String serverMachinePort = "1050";
            runAllTests(serverMachineName, serverMachinePort);
            
        } catch (Exception e) {
            System.out.println("ERROR : " + e) ;
            e.printStackTrace(System.out);
        }
    }
}
